set(TARGET_NAME "bootloader_pc")
set(TARGET_LIB "libbootloader_pc")

set(PROJECT_HEADERS
    s19file.h
    system_path.h
    bit_utils.h
    file_utils.h
    can_thread.h

    bootloader.h
    mainwindow.h
    settings.h
    configparser.h
)

set(PROJECT_SOURCES
    main.cpp
    widget.cpp
    widget.h
    widget.ui

    file_utils.cpp
    s19file.cpp
    can_thread.cpp

    bootloader.cpp
    mainwindow.cpp
    settings.cpp
    configparser.cpp
)

if(${QT_VERSION_MAJOR} GREATER_EQUAL 6) # >= 6
    qt_add_executable(${TARGET_NAME}
        MANUAL_FINALIZATION
        ${PROJECT_SOURCES}
        ${PROJECT_HEADERS}
        mainwindow.ui
        system_path.cpp
    )
else()
    add_executable(${TARGET_NAME}
        ${PROJECT_SOURCES}
        ${PROJECT_HEADERS}
        mainwindow.ui
    )
endif()

target_link_libraries(${TARGET_NAME} PRIVATE
    Qt${QT_VERSION_MAJOR}::Widgets
    Qt${QT_VERSION_MAJOR}::Core
    Qt${QT_VERSION_MAJOR}::SerialPort
    ${CAN_LIB_DIR}/lib/x64/ControlCAN.dll)

# Library for unit test
add_library(${TARGET_LIB} SHARED
    ${PROJECT_SOURCES}
    ${PROJECT_HEADERS}
    mainwindow.ui)
target_link_libraries(${TARGET_LIB} PRIVATE
    Qt${QT_VERSION_MAJOR}::Widgets
    Qt${QT_VERSION_MAJOR}::Core
    Qt${QT_VERSION_MAJOR}::SerialPort
    ${CAN_LIB_DIR}/lib/x64/ControlCAN.dll)


include(GNUInstallDirs)
install(TARGETS ${TARGET_NAME}
    BUNDLE DESTINATION .
    LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
    RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)

if(QT_VERSION_MAJOR EQUAL 6)
    qt_finalize_executable(${TARGET_NAME})
endif()
